//
//  PKGroupTableViewCell.m
//  PianKe
//
//  Created by mingtao on 15/10/12.
//  Copyright (c) 2015年 mingtao. All rights reserved.
//

#import "PKGroupTableViewCell.h"
#import <UIImageView+WebCache.h>

@implementation PKGroupTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _labletitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, WIHES, 40)];
        
        
        _labletitle.font = [UIFont systemFontOfSize:20];
        
        [self.contentView addSubview:_labletitle];
        
        
        _imageviewcoverimg = [[UIImageView alloc]init];
        
        _imageviewcoverimg.frame=CGRectMake(10, 55, 100, 100);
        
        [self.contentView addSubview:_imageviewcoverimg];
        
        _lablecontent=[[UILabel alloc]init];
        _lablecontent.frame = CGRectMake(120, 50, 250, 100);
       // _lablecontent.backgroundColor=[UIColor redColor];
        _lablecontent.numberOfLines=0;
        
        [self.contentView addSubview:_lablecontent];
        
        _lableaddtime_f=[[UILabel alloc]init];//initWithFrame:CGRectMake(10, 155, 40, 30)
        
        _lableaddtime_f.font = [UIFont systemFontOfSize:12];
        
        [self.contentView addSubview:_lableaddtime_f];
        
        _imageioc = [[UIImageView alloc]init];
        
       // _imageioc.frame = CGRectMake(300, 200, 30, 30);
        
        [self.contentView addSubview:_imageioc];
        
        _lablecomment=[[UILabel alloc]init];//initWithFrame:CGRectMake(340, 200, 35, 30)
        
        _lablecomment.font = [UIFont systemFontOfSize:12];
        
        [self.contentView addSubview:_lablecomment];
        
    }
    
    return self;

}
-(void)setGroupModel:(PKGrouplistModel *)GroupModel
{
    _GroupModel = GroupModel;
    _labletitle.text = GroupModel.title;
    
    [_imageviewcoverimg sd_setImageWithURL:[NSURL URLWithString:GroupModel.coverimg] placeholderImage:[UIImage imageNamed:@"AppIcon29x29@2x~ipad"]];
//
        _lablecontent.text = GroupModel.content;
    //自适应高度
    
   // CGFloat yheit=[PKGroupTableViewCell heightofString1:GroupModel.content];
  //  _lablecontent.frame = CGRectMake(120, 50, 250, yheit);
    
    _imageioc.image = [UIImage imageNamed:@"iconfont-liaotian"];
    _imageioc.frame = CGRectMake(300, 160, 30, 30);
    

    

    _lableaddtime_f.text = GroupModel.addtime_f;
    _lableaddtime_f.frame = CGRectMake(10, 160, 80, 30);
    
    _lablecomment.text =[NSString stringWithFormat:@"%lu",GroupModel.counterList.comment];
    _lablecomment.frame= CGRectMake(340, 160, 35, 30);
    
}


//自适应高度
+(CGFloat)heightofString1:(NSString *)introduce
{
    //    NSDictionary *dict=[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:23] forKey:NSFontAttributeName];
    //
    //    CGRect bounds = [str boundingRectWithSize:CGSizeMake(300, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dict context:nil];
    NSDictionary *dict =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    
    CGRect bounds=[introduce boundingRectWithSize:CGSizeMake(255, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    
    return bounds.size.height;
    
    
}



//给外界提供一个接口，返回cell的高度
+(CGFloat)heigHtforContact1:(PKGrouplistModel *)contact
{
    CGFloat heiht =150 +[self heightofString1:contact.content];
    if (heiht>=150) {
        return heiht;
    }else
    {
        return 150;
    }
    
    //return 95 +[self heightofString1:contact.introduce];
    
}



















- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
